'use strict'
const isInElectron = function () {
  return window && window.process && window.process.type
}

const strToQuotation = function (quotationString) {
  var sp = quotationString.split(',')
  var q = {}
  q['symbol'] = sp[0]
  q['market'] = sp[0].substring(0, 2)
  q['stockCode'] = sp[0].substring(2)
  q['stockName'] = sp[1]
  q['timestamp'] = parseInt(sp[2])
  q['preClosePrice'] = parseFloat(sp[3])
  q['hardenPrice'] = parseFloat(sp[4])
  q['deHardenPrice'] = parseFloat(sp[5])
  q['openPrice'] = parseFloat(sp[6])
  q['highPrice'] = parseFloat(sp[7])
  q['lowPrice'] = parseFloat(sp[8])
  q['nowPrice'] = parseFloat(sp[9])
  q['volume'] = parseInt(sp[10])
  q['amount'] = parseFloat(sp[11])
  q['totalTradeVolume'] = parseInt(sp[10])
  q['totalTradeAmount'] = parseFloat(sp[11])
  q['askVolume'] = parseInt(sp[12])
  q['bidVolume'] = parseInt(sp[13])
  q['totalTrades'] = parseInt(sp[14])
  q['orderNum'] = parseInt(sp[15])
  q['asks'] = []
  q['bids'] = []
  for (let i = 0; i < q['orderNum'] * 2; i += 2) {
    q['asks'].push({
      'volume': parseInt(sp[17 + i + q['orderNum'] * 2]),
      'price': parseFloat(sp[18 + i + q['orderNum'] * 2])
    })
  }
  for (let i = 0; i < q['orderNum'] * 2; i += 2) {
    q['bids'].push({
      'volume': parseInt(sp[17 + i]),
      'price': parseFloat(sp[18 + i])
    })
  }
  return q
}

export {
  isInElectron,
  strToQuotation
}
